package com.mnxc.gxa.config;

import com.mnxc.gxa.utils.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @BelongsProject: hm-dianping
 * @BelongsPackage: com.hmdp.config
 * @Author: mnxc
 * @CreateTime: 2023-06-10  22:33
 * @Description: Mvc配置类
 * @Version: 1.0
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    // @Resource
    // private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // Token刷新拦截器
        // registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate));
        // 用户验证拦截器
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/user/login",
                        "/swagger-ui.html",
                        "/webjars/**",
                        "/swagger-resources/**",
                        "/csrf",
//                        "/**",
                        "/v2/**"

                );
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("*")
                .allowedHeaders("*");
    }
}
